package com.wiz.web.service.impl;

import java.util.HashMap;
import java.util.Map;
import java.util.Random;

import javax.annotation.Resource;

import com.google.gson.Gson;
import com.wiz.common.Constant;
import com.wiz.common.ResponseCode;
import com.wiz.vo.TransimissionVO;
import com.wiz.vo.to.BaseObject;
import com.wiz.vo.to.ResultTO;

/**
 * 基类
 * @author Hakeny
 */
public abstract class BasicServiceImpl implements ResponseCode,Constant{
	
	@Resource
	protected Gson gson;
	
	public static Map<String,TransimissionVO> transMap = new HashMap<String,TransimissionVO>();
	
	/**
	 * 按照标准格式封装返回数据
	 * @param code
	 * @param msg
	 * @param o
	 * @return
	 */
	protected String returnResult(int code,String msg,BaseObject o) {
		if(o==null){
			o = new ResultTO();
		}
		o.setCode(code);
		o.setMsg(msg);
		return gson.toJson(o);
	}
	
	/**
	 * 获取纯数字随机串
	 * @param length
	 * @return
	 */
	protected int getRandom(int length) {
		Random rand = new Random();
		int num = (int) Math.pow(10, length-1);
    	int i = rand.nextInt(10*num-1);
    	if(i<num){
    		i+=num;
    	}
		return i;
	}
}
